<template>
  <div>
    <v-top></v-top>
    <v-nav></v-nav>
    <v-module>
      <slot>


        <div class='mv'>
          <!--      左边部分-->
          <div class='left'>
            <!--    标题-->
            <div class='title'>
              <h2>{{ data.title }}</h2>
              <span style='color:#999; font-size: 12px;margin-right: 5px'>by</span>
              <a style='color: #0c73c2' href=''> {{ name }}</a>
            </div>
            <!--    视频-->
            <div class='video'>
              <video style='background:black;border:none' controls autoplay preload width='640' height='360'
                     :src='mvurl'></video>
            </div>
            <!--    按钮-->
            <div class='btn'>
              <a href=''>
                <i>
                  <em></em>
                  ({{ msg.likedCount }})
                </i>
              </a>
              <a href=''>
                <i>
                  ({{ data.subscribeCount }})
                </i>
              </a>
              <a href=''>
                <i>
                  ( {{ msg.shareCount }} )
                </i>
              </a>
            </div>
            <!--    评论区-->
            <v-comment :commentCount='data.commentCount'></v-comment>
          </div>
          <!--      右边部分-->
          <div class='right'>
            <h3>mv简介</h3>
            <div class='introduce'>
              <p style='color: #999'>发布时间：{{ datatime }}</p>
              <p style='color: #999'>播放次数：{{ playtime }}万次</p>
              <p style='margin-top: 10px'> {{ data.desc }}{{ data.briefDesc }}</p>
            </div>
            <h3 style='margin-top: 20px;'>相关推荐</h3>
            <ul class='recommendation'>
              <li v-for='(item,index) in recommendation'>
                <div class='recommendation-left'>

                  <router-link :to="'/video/' + item.vid">
                    <img @click='next' width='96' height='54' :src='item.coverUrl' alt=''>

                  </router-link>
                  <p>

                    <span></span>
                    {{ (item.playTime / 10000).toFixed(2) }}万
                  </p>
                </div>
                <div class='recommendation-right'>
                  <router-link :to="'/video/' + item.vid">
                    <p @click='next'>{{ item.title }}</p>
                  </router-link>
                  <p style='color:#999;'>{{ mvtime[index] }}</p>
                  <p style='color:#999;;'>
                    by
                    <router-link :to="'/user/'+ item.creator[0].userId">
                      <a href='' style='color:#999;'>{{ item.creator[0].userName }}</a>
                    </router-link>
                  </p>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </slot>
    </v-module>
  </div>
</template>
<script>
import axios from 'axios'
import Top from '@/views/Top/Top'
import Nav from '@/views/Nav/Nav'
import module from '@/views/Module/module'
import config from '@/network/config'
import Comment from '@/views/Mv/Comment/VideoComment'
import moment from 'moment'

export default {
  name: 'Mv',
  components: {
    'v-top': Top,
    'v-nav': Nav,
    'v-module': module,
    'v-comment': Comment
  },
  data() {
    return {
      mvurl: '',
      url: config.url,
      data: [],
      playtime: '',
      name: '',
      datatime: '',
      recommendation: [], //相关推荐
      msg: '', //点赞数,
      mvtime: []
    }
  },
  methods: {
    getmv() {
      axios.get(`${this.url}/video/url?`, {
        params: {
          id: this.$route.params.id
        }
      }).then(res => {
        // console.log(res.data)
        this.mvurl = res.data.urls[0].url
      })
    },//获取mv链接
    async commenton() {
      let data = await axios.get(`${this.url}/video/detail?id=${this.$route.params.id}`)
      this.datatime = moment(data.data.data.publishTime).format('YYYY-MM-DD')
      this.playtime = (data.data.data.playTime / 10000).toFixed(2)
      this.data = data.data.data  //获取名字
      this.name = data.data.data.creator.nickname
    },    //获取mv数据
    async commendation() {
      let data = await axios.get(`${this.url}/related/allvideo?id=${this.$route.params.id}`)
      var list = []
      this.recommendation = data.data.data
      data.data.data.forEach(item => {
        list.push(item.durationms)
      }) //获取mv时间
      for (let i = 0; i < 5; i++) {
        this.mvtime.push(moment(list[i]).format('mm:ss'))
      }
      console.log(data.data.data)
    },//相关推荐的数据
    getmsg() {
      axios.get(`${this.url}/video/detail/info?vid=${this.$route.params.id}`).then(res => {
        this.msg = res.data
      })
    },
    next() {
      this.getmv()
      this.commendation()
      this.commenton()
      this.getmsg()
    }
  },
  mounted() {
    this.getmv()    //mv url
    this.commenton()   //mv 详情
    this.commendation() //相关推荐
    this.getmsg()
  }
}
</script>
<style scoped>

.recommendation-right p {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recommendation-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-left: 10px;
  overflow: hidden;

}

.recommendation-left {
  position: relative;
}

.recommendation-left p {

  position: absolute;
  display: flex;
  align-items: center;
  right: 0;
  justify-content: space-evenly;
  top: 0;
  color: white !important;
  text-shadow: -2px 1px rgb(0 0 0 / 40%);
  background: url("../../assets/images/mask.png");
  height: 20px;
  width: 90px;
  padding-right: 5px;
  line-height: 20px;
  box-sizing: border-box;
  text-align: right;
}

.recommendation-left p span {
  width: 15px;
  height: 10px;
  background: url("../../assets/images/icon2.png") -60px -310px;
  color: white;
}

.recommendation li {
  display: flex;
  height: 54px;
  margin-top: 10px;
}

/*相关推荐*/
.introduce p {
  text-align: justify !important;
}

.right p {
  color: #333;
  font-size: 12px;
  line-height: 18px;
}

.right h3 {
  height: 23px;
  margin-bottom: 20px;
  border-bottom: 1px solid #ccc;
  font-size: 12px;
  font-style: normal;
  color: #333;
  font-weight: 300px;
}

.right {
  box-sizing: border-box;
}

/*右边 */
.btn a em {
  display: block;
  background: url("../../assets/images/button2.png");
  width: 17px;
  height: 15px;
  margin: 8px 6px 0 0;
}


.btn a:nth-child(1) i em {
  background-position: 0 -95px !important;
}


.btn a:nth-child(1) {
  background-position: right -100px !important;
  color: #333;
}

.btn a:nth-child(1) i {
  display: flex;
  background-position: 0 -59px !important;
}

.btn a:nth-child(2) {
  background-position: right -100px !important;
  color: #333;
}

.btn a:nth-child(2) i {
  padding-right: 2px;
  padding-left: 28px;
  display: flex;
  background-position: 0 -977px;
}

.btn a:nth-child(3) {
  background-position: right -100px !important;
  color: #333;
}

.btn a:nth-child(3) i {
  padding-right: 2px;
  padding-left: 28px;
  display: flex;
  background-position: 0 -1268px;
}

.btn > a i {
  background: url("../../assets/images/button2.png");
  padding: 0 5px 0 10px;
  display: inline-block;
  *display: inline;
  *zoom: 1;
  height: 31px;
  line-height: 31px;
  overflow: hidden;
  *line-height: 32px;
  vertical-align: top;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-style: normal;
}

.btn > a {
  background: url("../../assets/images/button2.png");
  padding: 0 5px 0 0;
  display: inline-block;
  *display: inline;
  *zoom: 1;
  height: 31px;
  line-height: 31px;
  overflow: hidden;
  *line-height: 32px;
  vertical-align: top;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  margin-right: 10px;
}

.btn {
  margin-top: 10px;
}

/*按钮*/

.title h2 {
  font-size: 24px;
  max-width: 100%;
  margin-top: -10px;
  margin-right: 8px;
  line-height: 32px;
  font-weight: normal;
}

.title a {
  display: inline-block;
}

.title {
  padding-top: 10px;
  margin-bottom: 8px;
}

.title a:hover {
  text-decoration: underline;
}

.left .title a:nth-child(1) {
  display: block;
  width: 29px;
  height: 18px;
  background: url("../../assets/images/icon2.png") -230px -480px;
  margin-bottom: 5px;
  margin-right: 4px;
}


.right {
  width: 270px;
  padding: 20px 40px 40px 30px;
  border-left: 1px solid #eee;
}

.mv {
  width: 100%;
  height: 100%;
  display: flex;
}

.left {
  padding: 30px 30px 40px 39px;
}
</style>